package com.police.base;

import org.xutils.x;

import com.police.view.kprogresshud.KProgressHUD;

import android.app.Fragment;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


/** 
* @ClassName: BaseFragment 
* @Description: Fragment基类
* @author liming
* @date 2016年6月23日 上午11:08:03 
*  
*/ 
public class BaseFragment extends Fragment
{
    private boolean injected = false;
    protected KProgressHUD hud;
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState)
    {
        injected = true;
        // 创建默认的动作条
        hud = KProgressHUD.create(this.getActivity())
                  .setCancellable(true)
                  .setWindowColor(Color.argb(200, 165, 192, 247))
        		  .setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
        		  .setOnCancelListener(new OnCancelListener()
        		  {
					@Override
					public void onCancel(DialogInterface arg0) 
					{
						canceledHud();
					}
				});
        return x.view().inject(this, inflater, container);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState)
    {
        super.onViewCreated(view, savedInstanceState);
        if (!injected)
        {
            x.view().inject(this, this.getView());
            // 创建默认的动作条
            hud = KProgressHUD.create(this.getActivity())
                      .setCancellable(true)
                      .setWindowColor(Color.argb(200, 165, 192, 247))
            		  .setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
            		  .setOnCancelListener(new OnCancelListener()
            		  {
    					@Override
    					public void onCancel(DialogInterface arg0) 
    					{
    						canceledHud();
    					}
    				});
        }
    }
    
    /**   
     * @Title: dismissProgress   
     * @Description: 关闭进度条 
     * @param:       
     * @return: void      
     * @throws   
     */ 
    protected void dismissProgress()
	{
		if(hud != null)
    	{ 
			hud.dismiss();
    	}
	}
    
    
    /**   
     * @Title: canceledHud   
     * @Description: 取消进度条时，需要进行一些服务，重载该方法 
     * @param:       
     * @return: void      
     * @throws   
     */ 
    protected void canceledHud()
    {
    	
    }
}
